package fr.ssd.ci.ui.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;

import javax.swing.JTextField;

import fr.ssd.ci.certificat.Installer;

public class InstallAction implements ActionListener {

	private JTextField hostField;
	private JTextField keyStoreField;
	private JTextField passPhraseField;
	private Installer ci;

	public InstallAction(JTextField hostField, JTextField keyStoreField,
			JTextField passPhraseField, Installer ci) {
		this.hostField = hostField;
		this.keyStoreField = keyStoreField;
		this.passPhraseField = passPhraseField;
		this.ci = ci;
	}

	public void actionPerformed(ActionEvent e) {
		try {
			ci.installCertificat(hostField.getText().split(":")[0], Integer.parseInt(hostField.getText().split(":")[1]), passPhraseField.getText());
		} catch (KeyManagementException e1) {
			e1.printStackTrace();
		} catch (NumberFormatException e1) {
			e1.printStackTrace();
		} catch (KeyStoreException e1) {
			e1.printStackTrace();
		} catch (NoSuchAlgorithmException e1) {
			e1.printStackTrace();
		} catch (CertificateException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}

}
